function State(target: object, propertyKey: string) {
    // let value: any
    // Object.defineProperty(target, propertyKey, {
    //     get() {
    //         return value
    //     },
    //     set(newValue) {
    //         console.log(`${propertyKey}的最新值为：${newValue}`)
    //         value = newValue
    //     }
    // })

    // 解决问题后的代码
    let key = `__${propertyKey}`
    Object.defineProperty(target, propertyKey, {
        get() {
            return this[key]
        },
        set(newValue) {
            console.log(`${propertyKey}的最新值为：${newValue}`)
            this[key] = newValue
        },
        enumerable: true,
        configurable: true
    })
}

class Person {
    name: string
    @State age: number
    constructor(name: string, age: number) {
        this.name = name
        this.age = age
    }
}

const p1 = new Person('张三', 18)
const p2 = new Person('李四', 28)

p1.age = 30
p2.age = 40

// 注释代码存在问题 age会串
// 现存代码解决
console.log(p1.age, p2.age)
console.log(p1, p2)